//
//  YMSettingListCell.swift
//  YMMedical
//
//  Created by y s on 2023/7/25.
//

import UIKit

class YMSettingListCell: UITableViewCell {

    lazy var vBg: UIView = {
        let result = UIView()
        result.backgroundColor = STheme.D9;
        result.clipsToBounds = true
        result.layer.cornerRadius = SFitUtil.fit(8)
        return result
    }()
    lazy var lblTitle: UILabel = {
        let result = SThemeUtil.boldLabel("", color: STheme.H_D1, fontSize: 16)
        return result
    }()
    lazy var lblSub: UILabel = {
        let result = SThemeUtil.boldLabel("", color: STheme.H_D12, fontSize: 16)
        result.textAlignment = .right
        return result
    }()
    lazy var imgvArrow: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "tools_list_more_arrow")
        return result
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: -- UI
    func setUI() {
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        selectionStyle = .none

        contentView.addSubview(vBg)
        vBg.addSubview(lblSub)
        vBg.addSubview(lblTitle)
        vBg.addSubview(imgvArrow)
        
        vBg.snp.makeConstraints { make in
            make.left.equalTo(SFitUtil.fit(15))
            make.right.equalTo(SFitUtil.fit(-15))
            make.top.bottom.equalToSuperview()
        }
        lblTitle.snp.makeConstraints { make in
            make.left.equalTo(SFitUtil.fit(15))
            make.centerY.equalToSuperview()
        }
        lblSub.snp.makeConstraints { make in
            make.left.equalTo(lblTitle.snp.right).offset(SFitUtil.fit(10))
            make.centerY.equalToSuperview()
            make.right.equalTo(imgvArrow.snp.left)
        }
        imgvArrow.snp.makeConstraints { make in
            make.right.equalTo(SFitUtil.fit(-15))
            make.centerY.equalToSuperview()
            make.size.equalTo(SFitUtil.fitSize(24, height: 24))
        }
        
    }
    
    func updateData(_ dict: Dictionary<String, Any>){
        lblTitle.text = SDataUtil.stringOf(dict["title"])
        lblSub.text = SDataUtil.stringOf(dict["subTitle"])
    }
    public func hideArrow(_ isHide: Bool) {
        imgvArrow.isHidden = isHide
        if isHide {
            imgvArrow.snp.remakeConstraints { make in
                make.right.equalTo(SFitUtil.fit(-15))
                make.centerY.equalToSuperview()
                make.size.equalTo(SFitUtil.fitSize(0, height: 24))
            }
        }else{
            imgvArrow.snp.remakeConstraints { make in
                make.right.equalTo(SFitUtil.fit(-15))
                make.centerY.equalToSuperview()
                make.size.equalTo(SFitUtil.fitSize(24, height: 24))
            }
        }
    }
    
    public class func getCellHeight() -> CGFloat {
        return SFitUtil.fit(60)
    }
    
}
